import React from 'react';
import './index.scss';

import UserApi from "@/service/UserApi";

class Login extends React.Component {

    constructor(props) {
        super(props);

        this.submitLogin = this.submitLogin.bind(this);
        this.handleChange = this.handleChange.bind(this);

        this.state = {
            userName: 'admin',
            pwd: '888888'
        };

    }

    submitLogin() {

        UserApi.Login({
            userName: this.state.userName,
            pwd: this.state.pwd
        }).then(res => {
            localStorage.setItem('token', new Date().getTime());
            window.location.href = "/index.html";
        })


    }

    handleChange(event) {
        console.log(event)
        this.setState({ 'userName': event.target.value });
    }

    render() {
        return (
            <div className="compt LoginForm">

                <div className="line-wrap">
                    <input className="form-input" name="userName" value={this.state.userName} onChange={this.handleChange} />
                </div>

                <div className="line-wrap">
                    <input className="form-input" name="userName" value={this.state.pwd} onChange={this.handleChange} />
                </div>

                <div className="line-wrap">
                    {/* <input className="form-input" /> */}
                </div>

                <div className="line-wrap btn-wrap">
                    <button className="loginBtn" onClick={this.submitLogin}>
                        登陆
                    </button>
                </div>

            </div>
        );
    }
}
export default Login;